/*
 * Zadanie 3 4
 *
 * Samodzielnie zaimplementuj funkcję myStrdup. Działanie wyżej wymienionych funkcji jest dokładanie
 * takie samo jak w przypadku funkcji strdup z biblioteki string.h.
 *
 * strdup example
 * #include <stdio.h>
 * #include <string.h>
 *
 * #include <iostream>
 *
 * using namespace std;
 *
 * int main()
 * {
 *      char str[] = "This is a sample string";
 *      char *copy;
 *      copy = strdup(str);
 *      cout << "Original text: " << str << endl;
 *
 *      cout << "Copy: " << copy << endl;
 *
 *      delete copy;
 *
 *      cout << "Copy: " << copy << endl;
 *
 *      return 0;
 * }
 *
 * OUTPUT
 * Original text: This is a sample string
 * Copy: This is a sample string
 * Copy:
 *
 * Version: $Id: main.cpp 53 2011-11-11 06:06:00Z s8376@pjwstk.edu.pl $
 */
#include <iostream>
#include <string.h>

using namespace std;

char* myStrdup(char*);

int main(void)
{
    char str[] = "This is a sample string";
    char *copy;
    copy = myStrdup(str);
    cout << "Original text: " << str << endl;
    cout << "Copy: " << copy << endl;

    delete copy;

    cout << "Copy: " << copy << endl;

    return 0;
}

char* myStrdup(char* str)
{
    char* output = new char[strlen(str) + 1];
    char* marker = output;

    while (*str != 0) {
        *marker++ = *str++;
    }

    return output;
}
